package adminModel

import (
	"news_for_deepseek_interface/model"
	"time"
)

type AdminStruct struct {
	Id        int       `json:"id" gorm:"type:int(11) auto_increment; NOT NULL; primary_key"`
	Username  string    `json:"username" gorm:"type:varchar(32);  COMMENT:'用户名'"`
	Mobile    string    `json:"mobile" gorm:"type:varchar(32);  COMMENT:'手机号'"`
	Password  string    `json:"password" gorm:"type:varchar(32);  COMMENT:'密码'"`
	Salt      string    `json:"salt" gorm:"type:varchar(30);  COMMENT:'密码盐'"`
	Status    int       `json:"status" gorm:"type:varchar(30);  COMMENT:'状态'"`
	Expires   time.Time `json:"expires" gorm:"type:datetime; COMMENT:'到期时间'"`
	Province  string    `json:"province" gorm:"type:varchar(255); COMMENT:'省id'"`
	City      string    `json:"city" gorm:"type:varchar(255); COMMENT:'城市id'"`
	Area      string    `json:"area" gorm:"type:varchar(255); COMMENT:'地区id'"`
	Address   string    `json:"address" gorm:"type:varchar(255); COMMENT:'详细地址'"`
	CreatedAt time.Time `json:"created_at" gorm:"type:datetime"`
	UpdatedAt time.Time `json:"updated_at" gorm:"type:datetime"`
}

func (c *AdminStruct) TableName() string {
	return "admin"
}

// 根据手机号查询管理员id
func (c *AdminStruct) GetAdminByMobile(mobile string) (ids []int) {
	model.GetInstance().
		GetDB().
		Model(&AdminStruct{}).
		Where("mobile like ?", "%%"+mobile+"%%").
		Pluck("id", &ids)
	return
}
